/*
 * Copyright (c) 2020 hebeiyiliuba.com
 * All rights reserved.
 *
 */
package org.jeecg.modules.third.etc.waybillInfo.constant.enums;

import com.google.common.collect.Maps;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 车牌颜色
 *
 * @author duanlikao
 * @created 2021/1/28
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
public enum VehiclePlateColorEnum {
    VEHICLE_PLATE_COLOR_TYPE_BLUE(0,"1", "蓝色"),
    VEHICLE_PLATE_COLOR_TYPE_YELLOW(1,"2",  "黄色"),
    VEHICLE_PLATE_COLOR_TYPE_BLACK(2,"3",  "黑色"),
    VEHICLE_PLATE_COLOR_TYPE_WHITE(3, "4", "白色"),
    VEHICLE_PLATE_COLOR_TYPE_GRADIENT_GREEN(4, "94", "渐变绿色"),
    VEHICLE_PLATE_COLOR_TYPE_YELLOW_GREEN(5, "93", "黄绿渐变"),
    VEHICLE_PLATE_COLOR_TYPE_BLUE_WHITE(6,"14",  "蓝白渐变色"),
    VEHICLE_PLATE_COLOR_TYPE_NONE(9, "9", "未确定"),

    ;

    private  Integer code;
    private  String colortype ;
    private  String msg;

    private static Map <Integer, VehiclePlateColorEnum> codeMap = Maps.newHashMap();

    private static Map <String, VehiclePlateColorEnum> colortypeMap = Maps.newHashMap();

    public Integer getCode() {
        return this.code;
    }

    public String getColorType() {
        return this.colortype;
    }

    public String getDesc() {
        return this.msg;
    }

    public static String getMsg(Integer code) {
        return codeMap.containsKey(code) ? codeMap.get(code).getDesc() : StringUtils.EMPTY;
    }

    public static String getColorType(String colortype) {
        return colortypeMap.containsKey(colortype) ? colortypeMap.get(colortype).getColorType() : StringUtils.EMPTY;
    }



    public static boolean isValid(Integer code) {
        return codeMap.containsKey(code);
    }

    public static boolean isValidColorType(String colortype) {
        return colortypeMap.containsKey(colortype);
    }

    static {
        for (VehiclePlateColorEnum status : VehiclePlateColorEnum
                .values()) {
            codeMap.put(status.getCode(), status);
            colortypeMap.put(status.getColorType(), status);
        }
    }

    public static VehiclePlateColorEnum getVehiclePlateColorEnumByVal(Integer code) {
        return Arrays.stream(VehiclePlateColorEnum.values())
                .collect(Collectors.toMap(
                        VehiclePlateColorEnum::getCode, value -> value, (k1, k2) -> k2)).get(code);
    }

    public static VehiclePlateColorEnum getVehiclePlateColorEnumByType(String colortype) {
        return Arrays.stream(VehiclePlateColorEnum.values())
                .collect(Collectors.toMap(
                        VehiclePlateColorEnum::getColorType, value -> value, (k1, k2) -> k2)).get(colortype);
    }

//    public static void main(String[] args) {
//        VehiclePlateColorEnum vehiclePlateColorEnum =  VehiclePlateColorEnum.getVehiclePlateColorEnumByType("14");
//        System.out.println(vehiclePlateColorEnum);
//        System.out.println(vehiclePlateColorEnum.getCode());
//        System.out.println(VehiclePlateColorEnum.getColorType("14"));
//        System.out.println(vehiclePlateColorEnum.getColorType());
//        System.out.println(VehiclePlateColorEnum.isValidColorType("14"));
//    }
}